home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: bwmott@unity.ncsu.edu
- Newsgroups: comp.std.c++
- Subject: Forward declaration of a sub-class?
- Date: 6 Feb 1996 22:20:35 GMT
- Organization: ?
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <199602062218.RAA08320@pythagoras.csc.ncsu.edu>
- NNTP-Posting-Host: taumet.eng.sun.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset="US-ASCII"
- Content-Transfer-Encoding: 7bit
- X-Mailer: ELM [version 2.4 PL24/POP]
- X-Lines: 59
- Content-Length: 1277
- Originator: clamage@taumet
-
-
- I posted this to comp.std.c++, but I guess I was supposed to mail it
- so I'm mailing it now :-)
-
- [ Posting should work. If it doesn't, contact your site administrator
- to find out why. -mod ]
- --------------------------------------------------------------------------
-
-
- I've got a question about forward declaring a class as a sub-class of
- another class. Is it possible under the C++ draft standard to do
- something like:
-
- class S;
- class T : public S;
-
- The reason I need such a thing is because of the restrictions placed on
- redefining the return type of a virtual function.
-
- A simplified version of my class layout is:
-
- class S;
- class T; // This should be something to tell the compiler that
- // class T exists and that it's a subclass of S.
-
- class A {
- public:
- virtual S& belong() = 0;
- };
-
- class B : public A {
- public:
- virtual T& belong(); // This doesn't work but it seems
- // that it should be possible!
- private:
- T& myT;
- };
-
- class S {
- public:
- virtual A& get() = 0;
- };
-
- class T : public S {
- public:
- virtual B& get(); // This works fine
- private:
- B& myB;
- };
-
- I guess a possible solution would be for the redefinition test to be done
- on the definition instead of on the declaration.
-
- Is there any hope?
-
- Thanks,
- Bradford Mott
-
-
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
- summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
- ]
-